!-------------------------------------------------------------LICENSE--------------------------------------------------------------!
!                                                                                                                                  !
!The MAP code is written in Fortran language for magnetohydrodynamics (MHD) calculation with the adaptive mesh refinement (AMR)    !
!and Message Passing Interface (MPI) parallelization.                                                                              !
!                                                                                                                                  !
!Copyright (C) 2012                                                                                                                !
!Ronglin Jiang                                                                                                                     !
!rljiang@ssc.net.cn                                                                                                                !
!585 Guoshoujing Road. Pudong, Shanghai, P.R.C. 201203                                                                             !
!                                                                                                                                  !
!This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License         !
!as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.             !
!                                                                                                                                  !
!This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of    !
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.                        !
!                                                                                                                                  !
!You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software     !
!Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.                                                   !
!                                                                                                                                  !
!-------------------------------------------------------------LICENSE--------------------------------------------------------------!

!==================================================================================================================================|
module block_define
!==================================================================================================================================|

   use parameters
   implicit none

!----------------------------------------------------------------------------------------------------------------------------------|
   type block_pointer

      type(block), pointer :: pblock

   end type block_pointer

!----------------------------------------------------------------------------------------------------------------------------------|
   type block

      integer(4) :: lv = -1
      integer(4) :: cpu_id = 0
      integer(4) :: nx = 0, ny = 0
      integer(4) :: nc_x = 0, nc_y = 0, nc = 0
      integer(4) :: hilbert_number = 0
      integer(4), dimension(:), allocatable :: p_pos, start_pos, end_pos, start_point
      integer(4), dimension(:, :), allocatable :: id

      logical(4) :: var_allocate_flag = .false.

      real(8) :: dx, dy, dt, t, dt_hc, t_hc
      real(8), dimension(:), allocatable :: x, y
      real(8), dimension(:, :), allocatable :: ro, mx, my, mz, bx, by, bz, en, gx, gy, po, az
      real(8), dimension(:, :), allocatable :: ro0, mx0, my0, mz0, bx0, by0, bz0, en0, az0
      real(8), dimension(:, :), allocatable  :: fxro_bnd, fxmx_bnd, fxmy_bnd, fxmz_bnd,                                            &
         fxbx_bnd, fxby_bnd, fxbz_bnd, fxen_bnd, fxpo_bnd
      real(8), dimension(:, :), allocatable  :: fyro_bnd, fymx_bnd, fymy_bnd, fymz_bnd,                                            &
         fybx_bnd, fyby_bnd, fybz_bnd, fyen_bnd, fypo_bnd

      type(block), pointer :: parent => null (), last => null (), next => null ()
      type(block), pointer :: framework_next => null (), framework_last => null ()
      type(block_pointer), dimension(:, :), pointer :: child
      type(block_pointer), dimension(-1 : 1, -1 : 1) :: neigh

   end type block

!----------------------------------------------------------------------------------------------------------------------------------|
end module block_define
